package cn.wangzg.activitydemo;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

public class MainActivity extends BaseActivity {
    private static final String TAG = "MainActivity";
    TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.activity_main);
        //getSupportActionBar().hide();
        textView=findViewById(R.id.tv_second);
        Log.d(TAG, "onCreate: "+this.toString());
        if (savedInstanceState!=null){
            String text = savedInstanceState.getString("text");
            textView.setText(text);
        }

    }

    @Override
    protected void onStart() {
        Log.d(TAG, "onStart: ");
        super.onStart();
    }

    @Override
    protected void onResume() {
        Log.d(TAG, "onResume: ");
        super.onResume();
    }

    @Override
    protected void onPause() {
        Log.d(TAG, "onPause: ");
        super.onPause();
    }

    @Override
    protected void onStop() {
        Log.d(TAG, "onStop: ");
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        Log.d(TAG, "onDestroy: ");
        super.onDestroy();
    }

    @Override
    protected void onRestart() {
        Log.d(TAG, "onRestart: ");
        super.onRestart();
    }

    public void changeText(View view){
        Intent intent=new Intent(this,SecondActivity.class);
        startActivity(intent);
//        Intent intent=new Intent(this,SecondActivity.class);
//        intent.putExtra("a",111);
//        intent.putExtra("b",222);
//        startActivityForResult(intent,123);
        //overridePendingTransition(R.anim.anim_in,R.anim.anim_out);
        //textView.setText("android");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        int ret = data.getIntExtra("ret", 0);
        textView.setText(ret+"");
        super.onActivityResult(requestCode, resultCode, data);
    }

    public void gotoSecond(View view){

//        Intent intent=new Intent(this,SecondActivity.class);
//        startActivity(intent);
//        ComponentName cn = new ComponentName(
//                "cn.wangzg.activitydemo",
//                "cn.wangzg.activitydemo.SecondActivity") ;
//        Intent intent = new Intent() ;
//        intent.setComponent(cn) ;
//        startActivity(intent) ;

//        Intent intent = new Intent("android.intent.action.MAIN");
//        intent.setClassName(
//                "cn.wangzg.activitydemo",
//                "cn.wangzg.activitydemo.SecondActivity");
//        startActivity(intent);
//        Intent intent=new Intent("bbb");
//        startActivity(intent);
    }

    @Override
    protected void onSaveInstanceState(@NonNull Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString("text", textView.getText().toString());
    }
}